package net.sapfree.weibo;

public class WeiboHelper {
	
	
	public static String atReplace(String s){
		String s1=s;
		char at='@';
		int i=0;
		while(s.indexOf(at,i)!=-1){
			i=s.indexOf(at,i);
			int end=s.indexOf(')',i+1);
			if(end==-1){
				break;
			}
			String atStr=s.substring(i,end+1);
			if(atStr.indexOf('(')!=-1){
				int r=atStr.indexOf('(');
				int e=atStr.indexOf(')');
				String name=atStr.substring(0,r);
				String email=atStr.substring(r+1,e);
				String replaceStr="<A class=\"personLink\" href='person/personarea?email="+email+"'>"+name+"</A>";
				s=s.replace(atStr, replaceStr);
				i=end+1+replaceStr.length()-atStr.length();
			}else{
				i=end+1;
			}
		}
		return s;
	}

}
